package weixinkeji.dev.dc.buy.order.h.fwy;

import sys.wx.ann.hm.M;
import sys.wx.ann.power.head.SQ;
import sys.wx.c.ATR;
import sys.wx.c.components.check.bean.CheckData;
import sys.wx.c.components.cv.CV;
import sys.wx.m.db.SQL.mysql.common.where.Where;
import sys.wx.m.db.SQL.mysql.common.where.WhereConfig;
import sys.wx.m.db.dao.mysql.Dao;
import weixinkeji.dev.dc.DCPower;
import weixinkeji.dev.dc.buy.order.bean.FWYOrder;
import weixinkeji.dev.dc.buy.order.bean.FWYOrderB;
import weixinkeji.dev.dc.buy.order.so.FWYOrderSO;
import weixinkeji.dev.dc.buy.order.xy.FWYOrderXY;

@sys.wx.ann.hm.H("view/buy/order/fwy/kd/d")

//身份类型授权。无需人工付权。
//代表 是服务员才能进行访问。
@SQ(DCPower.ID_FWY)
public class FWYKDHD {

    @M("/dell")//通过 view/buy/order/fwy/kd/d/dell.imy 访问
    public static String dell(ATR a) {
        String order_id = CV.getParameter(a.request, "order_id", CheckData.ID);
        if (null == order_id) {
            return null;
        }

        FWYOrder rf = Dao.selectOneByID(FWYOrder.class, order_id);
        int selectCount = Dao.selectCount(FWYOrderB.class, Where.putThenGet(Where.TJ_IGNORE_NOTHING, null, "", "order_id", "=", order_id));
        if (rf.getOrder_sort().equals(FWYOrderXY.H_PAY_MONEY_ORDER)) {
            a.out_OK_NO(false, "订单已付款，无法删除");
            return null;
        } else if (rf.getOrder_sort().equals(FWYOrderXY.H_NEW_ORDER) && selectCount == 0) {
            a.out_OK_NO(Dao.dell(FWYOrder.class, order_id));
            //如果被删除订单正处于选择状态，清除选择
            Object id = a.session.getAttribute(FWYOrderXY.H_MYSELECT_ORDER);
            if (null != id && id.toString().equals(order_id)) {
                a.session.removeAttribute(FWYOrderXY.H_MYSELECT_ORDER);
            }
//            System.out.println(id + "//" + order_id);
            return null;
        } else if (selectCount > 0) {
            a.out_OK_NO(false, "订单正处于点餐中，如果确认要删除，请先清空该订单的菜");
            return null;
        } else {
            a.out_OK_NO(false, "订单已锁定，如果要删除，请通知管理员删除");
            return null;
        }
    }

    @M("/dellOrderB")//通过 view/buy/order/fwy/kd/d/dellOrderB.imy 访问
    public static String dellOrderb(ATR a) {
        Object id = a.session.getAttribute(FWYOrderXY.H_MYSELECT_ORDER);
        if (null == id) {
            a.printOne("请先选择订单！");
            return null;
        }
        
        String order_id = id.toString();
        Where w = new Where(new WhereConfig(""));
        w.put(Where.TJ_IGNORE_NOTHING, "", "order_id", "=", order_id)
                .put(Where.TJ_IGNORE_NOTHING, Where.AND, "orderb_style", "=", 1);
        boolean x = FWYOrderSO.dellOrderB_Style1(order_id);
        a.printOne(x ? "1" : "0");
        return null;
    }
}
